import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/home/Home.vue'

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err);
}

export default new Router({

	// mode: 'history',
	base: process.env.BASE_URL,

	routes: [
		//首页
		{
			path: '/',
			name: 'home',
			component: Home,
			meta: {
				title: "首页"
			},
		},

		{ //商品列表
			path: "/product/list",
			name: "product",
			meta: {
				title: "商品"
			},
			component: () => import( /* webpackChunkName: "product" */ '@/views/product/ProductList.vue')
		},
		{ // 商品详情
			path: "/product/detail",
			name: "productDetail",
			meta: {
				title: "商品详情"
			},
			component: () => import( /* webpackChunkName: "product" */ '@/views/product/ProductDetail.vue')
		},

		//购物车
		{
			path: "/shopcart",
			component: () => import( /* webpackChunkName: "shopcart" */ "@/views/shopcart/Shopcart.vue"),
			name: "shopcart",
			meta: {
				title: "购物车",
				requireAuth: true
			},
		},

		// 我的
		{
			path: "/user",
			component: () => import("@/views/user/User.vue"),
			name: "user",
			meta: {
				title: "我的"
			},
		},
		//登录
		{
			path: "/login",
			component: () => import("@/views/user/Login.vue"),
			name: "login",
			meta: {
				title: "登录"
			}
		},
		{ //用户注册
			path: "/register",
			component: () => import("@/views/user/Register.vue"),
			name: "register",
			meta: {
				title: "用户注册"
			}
		},
		//工作中提示
		{
			path: "/working",
			component: () => import("@/views/Working.vue"),
			name: "working",
			meta: {
				title: "努力中...."
			},
		},
		{ //个人资料
			path: "/ruser/profile",
			component: () => import("@/views/user/Profile.vue"),
			name: "profile",
			meta: {
				title: "个人资料"
			}
		},
		{ //修改密码
			path: "/user/updatePwd",
			component: () => import("@/views/user/UpdatePwd.vue"),
			name: "updatePwd",
			meta: {
				title: "修改密码"
			}
		},
		{
			path: "/order/create",
			component: () => import("@/views/order/OrderCreate.vue"),
			name: "orderCreate",
			meta: {
				title: "新建订单",
			},
		},
		{
			path: "/user/addressList",
			component: () => import("@/views/user/AddressList.vue"),
			name: "addressList",
			meta: {
				title: "收货地址列表",
				requireAuth: true
			}
		},
		{
			path: "/user/addressEdit/:id",
			component: () => import("@/views/address/AddressEdit.vue"),
			props: true,
			name: "addressEdit",
			meta: {
				title: "收货地址",
				requireAuth: true
			},
		},
		{
			path: "/order/list",
			component: () => import("@/views/order/OrderList.vue"),
			name: "orderList",
			meta: {
				title: "我的订单",
				requireAuth: true
			},
		},
		{
			path: "/order/detail/:id",
			component: () => import("@/views/order/OrderDetail.vue"),
			props: true,
			name: "orderDetail",
			meta: {
				title: "收订单详情",
				requireAuth: true
			},
		},
		//不存在路由提示
		//要放在最后
		{
			path: "*",
			name: "notFound",
			meta: {
				title: "导航页面不存在"
			},
			component: () => import( /* webpackChunkName: "notfound" */ '@/views/NotFound.vue')
		},

	],

})